const {
  addCourse,
  getCourseList,
  getHomeCourse,
  delCourse,
  updateCourse,
} = require("../controller/course");
const { SuccessModel, ErrorModel } = require("../model/resModel");
var express = require("express");
var router = express.Router();

const jwt = require("jsonwebtoken");
const loginCheck = require("../middleware/loginCheck");
const authCheck = require("../middleware/authCheck");
/* GET users listing. */

router.post("/add_course", (req, res, next) => {
  // console.log(req.body);
  const result = addCourse(req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("添加失败"));
    }
  });
});

router.get("/get_course", function (req, res, next) {
  const result = getCourseList(req.query.id);
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.get("/get_h_course", function (req, res, next) {
  const result = getHomeCourse();
  return result.then((val) => {
    res.json(new SuccessModel(val));
  });
});
router.get("/del_course", (req, res, next) => {
  const result = delCourse(req.query.id);
  // console.log(req.query.id);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel(val));
    } else {
      res.json(new ErrorModel("删除失败"));
    }
  });
});
router.post("/update_course", function (req, res, next) {
  const result = updateCourse(req.query.id, req.body);
  return result.then((val) => {
    if (val) {
      res.json(new SuccessModel());
    } else {
      res.json(new ErrorModel("更新失败"));
    }
  });
});
module.exports = router;
